// pages/marker/marker.js
var utils = require('../../utils/utils.js');
var id="";
var app = getApp();
var contentreply="";
 var lindex=0;
 var reply_id;
 var comment_id;
 var param;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info:{},
  },
  toDetailsTap: function (e) {
    id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/bookDetail/bookDetail?id=' + id,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log(options.markerId)
    this.getMarker(34);
    // 评论功能
    // this.comment();
    
    
  },
  gocontent:function(e){
    lindex=e.currentTarget.dataset.z;
    console.log(lindex);
    if (lindex==0){
      comment_id = e.currentTarget.dataset.comment_id;
    }else{
      reply_id = e.currentTarget.dataset.reply_id
    }
    console.log("comment_id" + comment_id)
    console.log("reply_id" + reply_id)
    this.setData({ lindex: lindex})
    
  },
  getcontent:function(e){
    contentreply = e.detail.value
  },
  // 评论功能
  comment:function(){
    var flag;
    var use=wx.getStorageSync('use');
    var that = this;
    if (lindex==0){
      param = {
        openid: use.openid,
        comment_id: comment_id,
        content: contentreply
      }
      that.setData({flag:0})
    }else{
      param = {
        openid: use.openid,
        comment_id: comment_id,
        content: contentreply,
        reply_id: reply_id
      }
      that.setData({flag: 1})
    }
    console.log(param)
    wx.request({
      url: app.globalData.url + 'addReply/',
      data: param,
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: (res) => {
        console.log(res);
        that.seeReply();
      },
      fail: function (res) {
        // fail
      }
    })
  },
  // 查看评论
  seeReply:function(){
    var that = this;
    var param = {
      comment_id: 11
    }
    wx.request({
      url: app.globalData.url + 'showReplies/',
      data: param,
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: (res) => {
        console.log(res);
        that.setData({ reply: res.data.replies})
      },
      fail: function (res) {
        // fail
      }
    })
  },
  // 点击地图的marker请求de数据
  getMarker: function (markerId) {
    var that = this;
    var param = {
      user_id: markerId,
    }
    wx.request({
      url: app.globalData.url + 'showUser/',
      data: param,
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      }, 
      success: (res) => {
        console.log(res);
        that.setData({info:res.data})
        // 查看评论
        that.seeReply();
      },
      fail: function (res) {
        // fail
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})